/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.advertisements_tag;

import com.apt.bean.Advertisements;
import com.apt.bean.Caste;
import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

/**
 *
 * @author Bach
 */
public class Get_Advertisements {

    public static HashMap<Integer, Advertisements> getListAdvertisements() {
        HashMap<Integer, Advertisements> listFB = new HashMap<Integer, Advertisements>();
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection conn = null;
//+ "Where [Advertisement_Status]= 1";
        String query = "SELECT  [Advertisement_Id]\n"
                + "      ,[Image_Id]\n"
                + "      ,[Expired_Date]\n"
                + "      ,[Created_Date]\n"
                + "      ,[Company_Issued]\n"
                + "      ,[Advertisement_Status]\n"
                + "  FROM [Matrimony].[dbo].[Advertisements] ";
                

        try {
            conn = Connect_DB.getConnection();
            if (conn != null) {
                ps = conn.prepareStatement(query);
                rs = ps.executeQuery();
                int key = 1;
                String advertisement_Id;
                String image_Id;
                String expired_Date;
                String created_Date;
                String company_Issued;
                String advertisement_Status;
                while (rs.next()) {
                    advertisement_Id = rs.getString("Advertisement_Id");
                    image_Id = rs.getString("Image_Id");
                    expired_Date = rs.getString("Expired_Date");
                    created_Date = rs.getString("Created_Date");
                    company_Issued = rs.getString("Company_Issued");
                    advertisement_Status = rs.getString("Advertisement_Status");
                    Advertisements fb = new Advertisements(advertisement_Id, image_Id, expired_Date, created_Date, company_Issued, advertisement_Status);
                    listFB.put(key, fb);
                    key++;
                }
            } else {
                System.out.println("Connect is null");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(rs, null, ps, conn);
        }
        return listFB;
    }
}
